package 适配器模式.impl;

import 适配器模式.AdvancedMediaPlayer;
import 适配器模式.MediaPlayer;

/**
 * 媒体适配器,实现媒体播放器接口
 */
public class MediaAdapter implements MediaPlayer {

    AdvancedMediaPlayer advancedMusicPlayer;

    /**
     * 媒体适配器
     *
     * @param audioType
     */
    public MediaAdapter(String audioType) {
        if (audioType.equalsIgnoreCase("vlc")) {
            advancedMusicPlayer = new VlcPlayer();
        } else if (audioType.equalsIgnoreCase("mp4")) {
            advancedMusicPlayer = new Mp4Player();
        }
    }

    /**
     * 播放
     *
     * @param audioType 播放类型
     * @param fileName  文件名称
     */
    @Override
    public void play(String audioType, String fileName) {
        if (audioType.equalsIgnoreCase("vlc")) {
            advancedMusicPlayer.playVlc(fileName);
        } else if (audioType.equalsIgnoreCase("mp4")) {
            advancedMusicPlayer.playMp4(fileName);
        }
    }
}
